package ch02.demo;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.Iterator;

public class Demo7 {
    Document doc=null;
        public void showInfo(){
            NodeList nodeList=doc.getElementsByTagName("Brand");
            for (int i=0;i<nodeList.getLength();i++){
                Node brand=nodeList.item(i);
                Element brandEle= (Element) brand;
                String brandStr=brandEle.getAttribute("name");
                NodeList types=brandEle.getChildNodes();
                for (int j=0;j<types.getLength();j++){
                    Node type=types.item(j);
                    if(type.getNodeType()==Node.ELEMENT_NODE){
                        Element typeEle=(Element) type;
                        String typeStr=typeEle.getAttribute("name");
                        System.out.println("手机:"+brandStr+typeStr);
                }
            }
        }
    }
}
